package com.fangshuoit.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by Fangshuo_zhou on 2018/2/3.
 */
@Aspect
@Component
public class TimeAspect {

    @Around("execution(* com.fangshuoit.web.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("time aspect start");
        long start = new Date().getTime();
        //获取方法的参数
        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            System.out.println("arg is:" + arg);
        }
        //获取返回值
        Object object = pjp.proceed();
        System.out.println("time aspct 耗时:" + (new Date().getTime() - start));
        System.out.println("time aspect end");
        return object;
    }
}
